<?php
session_start();
include 'style/top.php'; 
include ('style/menu.php');
include ('style/left.php');
?>
<div class="content">

<?php
    if(isset($_POST['postdangnhap'])){
    if(isset($_POST['tendn']) && isset($_POST['passdn'])){
    
        $unam = trim(strtolower($_POST['tendn']));
        $upass = trim(strtolower(md5($_POST['passdn'])));
        $sl = "select * from thanhvien where u_name = '$unam' and u_pass = '$upass'";
         $chonsl = mysql_query($sl);
         $num = mysql_fetch_row($chonsl);
         if($num['0'] != 0 ){
            $sl1 = "select * from thanhvien where u_name ='$unam' and u_pass = '$upass'";
            $chonsl1 = mysql_query($sl1);
            $row = mysql_fetch_assoc($chonsl1);
            
            $tendangnhap = $row['u_name'];
            $mkdangnhap = $row['u_pass'];
            $tentv = $row['hoten_tv'];
            $idtv = $row['id'];
            
            if($unam == $tendangnhap && $upass == $mkdangnhap){
                
                $_SESSION['tentv'] = $tentv;
                $_SESSION['tendntv'] = $tendangnhap;
                $_SESSION['idtv'] = $idtv;
                echo "<script> window.location = 'index.php'</script>";
            }else{
                echo "chưa có nội dung";
            }
            }else{
                echo "<script> alert('Sai tên đăng nhập hoặc mật khẩu.Hoặc bạn chưa có tài khoản !');</script>";
                echo "<script> window.location = 'dangnhapthanhvien.php?user=add'</script>";
            }
         }
  
    }
    $dkuser = $_GET['user'];
    if($dkuser == 'add'){
    if($_SESSION['idtv'] == ''){
          echo "<div class ='dangkythanhvien'>";
                echo "<div class ='tieudedangky'> Đăng ký thành viên</div>";
                echo "<form name ='frmtv' method ='post' action ='' onsubmit='return validdangkytv();'>";
                    echo "<table style='width: 580px; margin-left : 80px;'>";
                        echo "<tr>";
                        echo "<td class = 'tdthanhvien1'>User name :</td>";
                        echo "<td><input class ='tdthanhvien2 input ' type ='text' id ='tentv_dk' name ='tendangky'  /></td>";
                        echo "</tr>";    
                        
                        echo "<tr>";
                        echo "<td class = 'tdthanhvien1'>Password:</td>";
                        echo "<td><input class ='tdthanhvien2 input' type ='password' id ='pass_dk' name ='mkdangky'  /></td>";
                        echo "</tr>";    
                        
                        echo "<tr>";
                        echo "<td class = 'tdthanhvien1'>Họ và tên :</td>";
                        echo "<td><input class ='tdthanhvien2 input' type ='text' id ='hvtentv_dk' name ='hvtdangky'  /></td>";
                        echo "</tr>";    
                        
                        echo "<tr>";
                        echo "<td class = 'tdthanhvien1'>Địa chỉ :</td>";
                        echo "<td><input class ='tdthanhvien2 input' type ='text' id ='dctv_dk' name ='dcdangky'  /></td>";
                        echo "</tr>";   
                        
                        echo "<tr>";
                        echo "<td class = 'tdthanhvien1'>Điện thoại :</td>";
                        echo "<td><input class ='tdthanhvien2 input' type ='text' id ='dttv_dk' name ='dtdangky'  /></td>";
                        echo "</tr>";  
                        
                        echo "<tr>";
                        echo "<td class = 'tdthanhvien1'>Email :</td>";
                        echo "<td><input class ='tdthanhvien2 input' type ='text' id ='emailtv_dk' name ='emaildangky'  /></td>";
                        echo "</tr>"; 
                         
                         echo "<td colspan ='2' align ='left'>";
                         echo "<input type ='submit' class ='edit smdk' name ='dangkythanhvien' value ='Đăng ký' />";
                         echo "</td>";
                    echo "</table>";
                echo "</form>";
            echo "</div>"; 


          }
         
      }
// bat bien insert thanh vien 
if(isset($_POST['dangkythanhvien'])){
    
    
          $unamedk = addslashes($_POST['tendangky']);
          $upassdk = md5($_POST['mkdangky']);
          $uhotendk = addslashes($_POST['hvtdangky']);
          $udiachidk = addslashes($_POST['dcdangky']);
          $udienthoaidk = addslashes($_POST['dtdangky']);
          $uemaildk = addslashes($_POST['emaildangky']);
          $datedk = date('d-m-Y');
         
            
         $sldb = "INSERT INTO thanhvien VALUES(0,'".$unamedk."','".$upassdk."','".$uhotendk."','".$udiachidk."','".$udienthoaidk."','".$uemaildk."','".$datedk."')";
         $isernttv = mysql_query($sldb) or die ("không insert được thành viên".mysql_error());
          if($isernttv){
            echo "<script> window.location = 'index.php'</script>";
            }else{
               echo "<div class ='kiemtradn'>Bạn không thể đăng ký được</div>";
                }
    
}      
      
?>
</div>
<?php

include ('style/right.php');
include ('style/bottom.php');
?>